<?php

declare(strict_types=1);
namespace App\Controller\Admin\Test;


use App\Controller\Admin\AbstractController;
use App\Dto\Admin\Test\TestBodyDto;
use App\Dto\Admin\Test\TestFormDto;
use App\Dto\Admin\Test\TestQueryDto;
use App\Logic\Admin\User\UserLogic;
use App\Vo\DataSubmitVo;
use App\Vo\Test\TestQueryVo;
use Hesb\Hyperf\ApiDocs\Annotation\Api;
use Hesb\Hyperf\ApiDocs\Annotation\ApiOperation;
use Hesb\Hyperf\ApiDocs\Annotation\ApiResponse;
use Hesb\Hyperf\DTO\Annotation\Contracts\RequestBody;
use Hesb\Hyperf\DTO\Annotation\Contracts\RequestFormData;
use Hesb\Hyperf\DTO\Annotation\Contracts\RequestQuery;
use Hesb\Hyperf\DTO\Validation\Annotation\Contracts\Valid;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Api(tags: '测试')]
#[Controller(prefix:"/api/admin/test/test",server:"admin")]
class TestController extends AbstractController
{
    #[Inject]
    protected UserLogic $logic;

    #[ApiOperation('测试query')]
    #[GetMapping(path: 'query')]
    #[ApiResponse(TestQueryVo::class)]
    public function query(#[RequestQuery] TestQueryDto $dto){
        //逻辑层高处理对象
        $params = get_object_vars($dto);
        $params['time'] = time();
        var_dump($params);
        //逻辑层返回数组
        //根据响应对象，约束响应数据
        return $this->success($params);
    }

    #[ApiOperation('测试body')]
    #[PostMapping(path: 'body')]
    #[ApiResponse(DataSubmitVo::class)]
    public function body(#[RequestBody] #[Valid] TestBodyDto $dto){
        $result =$this->logic->add($dto);
        //逻辑层返回数组
        //根据响应对象，约束响应数据
        return $this->success($result);
    }

    #[ApiOperation('测试form')]
    #[PostMapping(path: 'form')]
    #[ApiResponse(DataSubmitVo::class)]
    public function form(#[RequestFormData] #[Valid] TestFormDto $dto){
        var_dump($dto);
        $result = [
            'result' => true,
            "sss"    => 1111,
        ];
        //逻辑层返回数组
        //根据响应对象，约束响应数据
        return $this->success($result);
    }

}
